package Test_1111;

import Test_1106.MySingleList;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
class ListNode {
    int val;
    ListNode next = null;
    ListNode(int val) {
        this.val = val;
    }
}
public class Partition {
    public ListNode partition(ListNode pHead, int x) {
        ListNode list1=new ListNode(0);
        ListNode last1=list1;
        ListNode list2=new ListNode(0);
        ListNode last2=list2;
        ListNode cur=pHead;
        while (cur!=null){
            ListNode next=cur.next;
            if(cur.val<x){
                last1.next=cur;
                cur.next=null;
                cur=next;
                last1=last1.next;
            }else{
                last2.next=cur;
                cur.next=null;
                cur=next;
                last2=last2.next;
            }
        }
        last1.next=last2.next;
        return list1.next;
    }
}

